package me.zk.practice1.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zhangkai
 * @date 2023/7/18 11:15
 */
public class ThreadPoolDemo {
    public static void main(String[] args) throws InterruptedException {
//        Executors.newWorkStealingPool().submit();
       System.out.println(1 << 27);
        AtomicInteger ai = new AtomicInteger(0);
        Object lock = new Object();

        CompletableFuture.runAsync(() ->{
           while (ai.get()<100) {
               synchronized (lock) {
                   System.out.println(ai.get() + ":a");
                   ai.getAndIncrement();
                   try {
                       lock.wait();
                       lock.notifyAll();

                   } catch (InterruptedException e) {
                       throw new RuntimeException(e);
                   }
               }


           }
        });
        CompletableFuture.runAsync(() ->{
            while (ai.get()<100) {
                synchronized (lock) {
                    System.out.println(ai.get() + ":b");
                    ai.getAndIncrement();
                    try {
                        lock.notifyAll();
                        lock.wait();

                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            }
        });
    }

}
